package middle;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution_187 {

    public List<String> findRepeatedDnaSequences(String s) {
        Set<String> set = new HashSet<>();
        Set<String> exists = new HashSet<>();
        for (int i = 0; i < s.length() - 10; i++) {
            String str = s.substring(i, i + 10);
            if (!set.contains(str)) {
                if (exists.contains(str)) {
                    set.add(str);
                } else {
                    exists.add(str);
                }
            }
        }
        return new ArrayList<>(set);
    }

    public static void main(String[] args) {
        Solution_187 model = new Solution_187();
        System.out.println(model.findRepeatedDnaSequences("AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"));
        System.out.println(model.findRepeatedDnaSequences("AAAAAAAAAAAAA"));
    }
}
